package com.oxylusflash.AccordionMenu
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import caurina.transitions.Tweener;
	
	
	public class SmallThumb extends Sprite
	{
		public var Shape:Sprite;
		public var bmp:BitmapData;
		public var sPreLoader:Sprite;
		private var imgLoader:Loader;
		private var Img:Sprite;
		private var newH:Number;
		private var newW:Number;
		
		//constructor
		public function SmallThumb()
		{
			
		}
		
		//set image path
		public function setImage(path:String,tw:Number,th:Number):void
		{
			newW = tw;
			newH = th;
			imgLoader = new Loader();
			imgLoader.contentLoaderInfo.addEventListener(Event.INIT, imgLoader_initHandler, false, 0, true);
			if (path>"") imgLoader.load(new URLRequest(path));
		
		}
		
		//handler for the image load complete event
		private function imgLoader_initHandler(e:Event):void 
		{
			var ow:Number = imgLoader.content.width;
			var oh:Number = imgLoader.content.height;
			bmp = new BitmapData(ow, oh, true, 0);
			bmp.draw(imgLoader.content);
			Img = new Sprite();
			
			Shape.addChild(Img);
			Img.alpha = 0;
			Tweener.addTween(Img, { alpha:1, time: 0.5, transition: "easeoutquad" } );
			Tweener.addTween(sPreLoader, { alpha:0, time: 0.2, transition: "easeoutquart" });
			Img.addChild(new Bitmap(bmp, "auto", true ));
			resize(newW, newH);
			Img.x = 1;
			Img.y = 1;
			
			
		}
		
		//resize holder and image
		public function resize(w:Number, h:Number):void
		{
			Shape.width = w;
			Shape.height = h;
			sPreLoader.x = w / 2;
			sPreLoader.y = h / 2;
			try 
			{
				Img.width = w - 2;
				Img.height = h - 2;
			}
			catch (er:Error) {}
			
		}
		
	}
}